package com.doge.calcalbum.business.album.migrate

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.doge.calcalbum.R
import com.doge.calcalbum.core.base.adapters.AdapterCallback
import com.doge.calcalbum.core.base.adapters.ITEM_CLICKED
import com.doge.calcalbum.core.base.adapters.ITEM_LONG_CLICKED
import com.doge.calcalbum.databinding.CellAlbumMigrateBinding
import com.doge.calcalbum.db.model.Album
import com.doge.calcalbum.utils.getString
import com.doge.calcalbum.utils.load
import com.doge.calcalbum.utils.setOnClickCallback

class AlbumMigrateViewHolder(
    parent: ViewGroup,
    callback: AdapterCallback,
    private val binding: CellAlbumMigrateBinding = CellAlbumMigrateBinding.inflate(
        LayoutInflater.from(parent.context),
        parent,
        false
    ),
) : RecyclerView.ViewHolder(binding.root) {
    init {
        binding.item.setOnClickCallback {
            callback.invoke(ITEM_CLICKED, itemView.tag)
        }
        binding.item.setOnLongClickListener {
            callback.invoke(ITEM_LONG_CLICKED, itemView.tag)
            true
        }
    }

    fun bind(item: Album) {
        itemView.tag = item
        binding.count.text = String.format(getString(R.string.xxx_picture_count), item.count.toString())
        binding.title.text = item.title
        binding.cover.load(
            item.cover,
            placeHolder = R.mipmap.album_picture_empty,
        )
    }
}